#!/usr/bin/env python
# -*- coding: utf-8 -*-

import paramiko


class SshSimple:
    def __init__(self,hosts,username,password,port):
        self.hosts = hosts
        self.username = username
        self.password = password
        self.port = port
    
    def main(self):
        #key 定义私钥存放路径
        #privatekey = os.path.expanduser('~/.ssh/id_rsa') 
        #key = paramiko.RSAKey.from_private_key_file(privatekey)
        paramiko.util.log_to_file("syslogin.log")
        ssh = paramiko.SSHClient()
        ssh.load_system_host_keys() #加载系统默认的host_keys
        ssh.connect(hostname=self.hosts,username=self.username,password=self.password,port=self.port)
        #ssh.connect(hostname=self.hosts,username=self.username,password=self.password,port=self.port,pkey=key)
        stdin,stdout,stderr = ssh.exec_command("ls -l")
        print(stdout.read())
        ssh.close()

if __name__ == '__main__':
    hosts = input("请输入主机地址：")
    username = input("请输入用户名：")
    password = input("请输入密码：")
    port = input("请输入端口号：")
    ssh = SshSimple(hosts,username,password,port)
    ssh.main()